package edu;

import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

public class browse extends JFrame {
    private static final long serialVersionUID = -1928970409928880648L;

    Connection conn = null;
    Connection conn1 = null;
    PreparedStatement ps = null;
    PreparedStatement ps1 = null;
    ResultSet res = null;
    ResultSet res1 = null;
    JTable jtable;
    JScrollPane jscrollpane = new JScrollPane();

    Vector columnNames = null;
    Vector rowData = null;

    public browse() {
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));

        columnNames = new Vector();
        columnNames.add("工      号：");
        columnNames.add("姓      名：");
        columnNames.add("性      别：");
        columnNames.add("年      龄：");
        columnNames.add("大      学：");
        columnNames.add("初      中：");
        columnNames.add("高      中：");
        columnNames.add("大      学：");
        columnNames.add("硕      士：");
        columnNames.add("博      士：");
        columnNames.add("学      位：");
        rowData = new Vector();

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/work","root","123456");
            conn1 = DriverManager.getConnection("jdbc:mysql://localhost:3306/work","root","123456");
            ps = conn.prepareStatement("SELECT allstaff.pno,`name`,xingbie,age,xxm,czm,gzm,dxm,ssm,bsm,xueli FROM allstaff,xx,cz,gz,dx,ss,bs WHERE allstaff.pno=xx.pno AND allstaff.pno=cz.pno AND allstaff.pno=gz.pno AND allstaff.pno=dx.pno AND allstaff.pno=ss.pno AND allstaff.pno=bs.pno;");
            res = ps.executeQuery();
            while (res.next())
            {

                Vector hang = new Vector();
                hang.add(res.getString(1));
                hang.add(res.getString(2));
                hang.add(res.getString(3));
                hang.add(res.getString(4));
                hang.add(res.getString(5));
                hang.add(res.getString(6));
                hang.add(res.getString(7));
                hang.add(res.getString(8));
                hang.add(res.getString(9));
                hang.add(res.getString(10));
                hang.add(res.getString(11));
                rowData.add(hang);
            }
            System.out.println("load  ok!");
        }catch (Exception q){
            q.printStackTrace();
            System.out.println("go die");
        }finally{
            try{
                res.close();
                ps.close();
                conn.close();
                conn1.close();
                System.out.println("close ok");
            }catch (SQLException o){
                o.printStackTrace();
                System.out.println("go die 2");
            }
        }
        jtable = new JTable(rowData,columnNames);
        jscrollpane = new JScrollPane(jtable);

        this.add(jscrollpane);
        this.setTitle("员工学籍信息");
        this.setLayout(new GridLayout(2,7));
        this.add(jpforbutton);
        this.setLocation(300,300);
        this.setSize(1000,400);
        this.setVisible(true);
        this.setResizable(false);
    }
}

